#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
const int N = 1e4+10;
int dp[N];
int main() {
    for(int i=1;i<N;i++)
    {
        dp[i]=1e9;
        int t=sqrt(i);
        for(int j=1;j<=t;j++)
        {
            dp[i]=min(dp[i],dp[i-j*j]+1);
        }
    }
    int n;
    cin >> n;
    cout << dp[n] << endl;
    return 0;
}